# == Schema Information
#
# Table name: roles
#
#  id         :integer          not null, primary key
#  name       :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#


class Role < ApplicationRecord

  RESERVED = [ :admin, :guest, :designer ]

  has_many :role_resources, dependent: :destroy
  has_many :user_roles, dependent: :destroy
  has_many :users, through: :user_roles

  validates :name, uniqueness: true

  class << self

    def all_without_reserved
      self.all.reject do |role|
        RESERVED.include?(role.name)
      end
    end

    def get_admin_users
      Role.find_by_name('admin').users
    end

    def get_designer_role
      Role.where(name: "designer").first
    end

    def get_admin_role
      Role.where(name: "admin").first
    end

  end

end
